# -*- coding:UTF-8 -*-
# coding:utf-8
import scrapy
from scrapy_test.items import ImageItem
import sys
reload(sys)
sys.setdefaultencoding('utf-8')


## scrapy 流程示意

class ComicSpider(scrapy.Spider):
	name = "oschina"
	# 减慢爬取速度 为1s
	download_delay = 1
	allowed_domains = ["www.douban.com"]
	start_urls = ['https://music.douban.com/artists/genre_page/5/']


	def start_requests(self):
		self.log('>>>>>>>引擎获取URL——自定义spider中start_urls列表中获取 1')

		urls = ['https://www.douban.com/photos/photo/2498078024/','https://www.douban.com/photos/photo/2498096224/']
		for url in urls:
			yield scrapy.Request(url=url, callback=self.parse)

	def parse(self, response):
		##item=ScrapyTestItem()  $('.hot_blog li a')[1].text
		## 返回list
		## 返回生成器
		## 返回字典
		## scrapy.Request
		l =ImageItem()
		#items=[]
		self.log('>>>>>>>在自定义spider中调用默认的parse()方法或是制定的parse_*()方法处理接收到的reponse 4')
		article_url = response.css('.image-show img::attr(src)').extract_first()
		article_name = response.xpath('//div[@id="article_details"]/div/h1/span/a/text()').extract()
		l['images']=[article_name]
		l['image_urls']= [article_url]
		return l

	def get_title(self,response):
		print response.url

